﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DataHelper;
using Utils;

namespace DAL
{
   public  class CourseDao
    {
        public bool Insert(string tableName, SortedDictionary<string, string> sdList)
        {
            return new BuiltSQL().InsertTable(tableName, sdList);
        }


        public bool Update(string tableName, SortedDictionary<string, string> sdList)
        {
            return new BuiltSQL().UpdateTable(tableName, sdList);
        }

        public bool DeleteOneInfo(string courseID)
        {
            return SQLHelper.ExecuteSqlWithTransaction("Delete from Admin_Train_Course Where CourseID=" + courseID);
        }
        //获取一条记录
        public DataTable GetOneInfo(string courseID)
        {
            return SQLHelper.ExecuteSqlGetDrToDt("Select * from Admin_Train_Course Where CourseID=" + courseID);
        }
        //SQL
        public string GetSQL(string serWord, string statu)
        {

            StringBuilder strSQL = new StringBuilder("Select a.*,b.Name as TypeName From Admin_Train_Course a,Admin_Train_Type b Where a.TypeID=b.ID and a.statu like '%" + statu + "%' ");
            if (!string.IsNullOrWhiteSpace(serWord))
                strSQL.Append(" And (a.CourName Like '%" + serWord + "%')");

            return strSQL.ToString();
        }
        //列表
        public DataTable GetLists(string serWord, string statu)
        {
            DataTable dt = SQLHelper.ExecuteSqlGetDrToDt(GetSQL(serWord, statu));
            return dt;
        }
    }
}
